<?php
class X_BrowserDetect{
    private static $name= null;
    private static $version= null;
    private static $detected= false;
    private static $browsers= array(
        
        "firefox",
        "msie",
        "opera",
        "chrome",
        "safari",
        
        "mozilla",
        "seamonkey",
        "konqueror",
        "netscape",
        "gecko",
        "navigator",
        "mosaic",
        "lynx",
        "amaya",
        "omniweb",
        "avant",
        "camino",
        "flock",
        "aol",
        
        );
    
    private static function detect(){
        if(X_BrowserDetect::$detected)return;
        $agent= strtolower($_SERVER['HTTP_USER_AGENT']);
        foreach(X_BrowserDetect::$browsers as $browser){
            if(preg_match('#('.$browser.')[/ ]?([0-9.]*)#', $agent, $match)){
                X_BrowserDetect::$name= $match[1];
                X_BrowserDetect::$version= $match[2];
                break;
            }
        }
        X_BrowserDetect::$detected= true;
    }
    
    public static function getName(){
        X_BrowserDetect::detect();
        return X_BrowserDetect::$name;
    }
    public static function getVersion(){
        X_BrowserDetect::detect();
        return X_BrowserDetect::$version;
    }
    public static function getBrowserNames(){
        return X_BrowserDetect::$browsers;
    }
    
}
